<?php
defined( '_JEXEC' ) or die( 'Restricted access' );

	//require_once('admin.php'); 
	 
	$title = __('Dashboard');
	
	//////////// 1.5 ////////////////
	/**
	 * this is the 'view'
	 * moved requires back to admin.mojo.php
	 */
	
	$reg = JRegistry::getInstance('mojo');
	$admin_path = $reg->getValue('config.admin_path',JPATH_ADMINISTRATOR.DS.'components'.DS.'com_mojo'.DS.'wp-admin');
	$abspath = $reg->getValue('config.abspath');
	$wpinc = $reg->getValue('config.wpinc_path');
	$option = JRequest::getWord('option');
	$task = JRequest::getWord('task');
	$uri_array= array(
		'option'		=> $option,
		'task'			=> $task,
		'controller'	=> $controller,
	);
	$uri =& JURI::getInstance(); 
	$uri->setQuery($uri_array); 
	
	global $wpdb;
	$wpdb = $reg->getValue('mojo_db',$wpdb);
	
	require_once($mojo_exec_point.DS.'admin-header.php');
	require_once ($abspath.DS.$wpinc.DS.'rss-functions.php');
	///////////////////////////////
	
	//require_once('admin-header.php');
	//require_once (ABSPATH . WPINC . '/rss-functions.php');
	
	$today = current_time('mysql', 1);
?>

<div id="viewport" class="wrap">
	<h2><?php _e('Dashboard'); ?></h2>
<!--LATEST STATS-->	
	<div id="mojoStats">
		<h2><?php _e('Latest Activity'); ?></h2>
		<?php
			// $rss = @fetch_rss('http://feeds.technorati.com/cosmos/rss/?url='. trailingslashit(get_option('home')) .'&amp;partner=mojoblog');
				 if ( isset($rss->items) && 0 != count($rss->items) ) {
		?>
<!--INCOMING LINKAGE-->	
	<div id="incominglinks">
	<h3><?php _e('Incoming Link Love'); ?>
		<cite>
		<a href="http://www.technorati.com/cosmos/search.html?url=<?php echo trailingslashit(get_option('home')); ?>&amp;partner=mojoblog"><?php _e('More'); ?> &raquo;</a>
		</cite>
	</h3>
	<ul>
		<?php
			$rss->items = array_slice($rss->items, 0, 10);
			foreach ($rss->items as $item ) {
		?>
		<li><a href="<?php echo wp_filter_kses($item['link']); ?>"><?php echo wp_specialchars($item['title']); ?></a></li>
		<?php } ?>
	</ul>
	</div><!--/end linkage report-->
	<?php } ?>
<!--RECENT COMMENTS-->
	<?php
	$comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 5");
	$numcomments = $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_approved = '0'");
		if ( $comments || $numcomments ) :
	?>

	<div id="recentcomments">
		<h3><?php _e('Recent Comments on my posts'); ?>
			<a href="edit-comments.php" title="<?php _e('More comments...'); ?>">&raquo;</a>
		</h3>
		<?php if ( $numcomments ) : ?>
<!--COMMENTS 2 MODERATE-->
		<p class="moderate">
			<a href="moderation.php"><?php echo sprintf(__('Comments in moderation (%s)'), number_format($numcomments) ); ?> &raquo;</a>
		</p>
		<?php endif; ?>
	</div>

	<ul>
		<?php 
			if ( $comments ) {
				foreach ($comments as $comment) {
					echo '<li>' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. 'permalink_ref' . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>'); edit_comment_link(__("Edit"), ' ','');  echo '</li>';
				}//get_permalink($comment->comment_post_ID)
			}
		?>
	</ul>

	<?php endif; ?>
<!--RECENT POSTS-->
	<?php
		if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 5") ) :
	?>

	<div id="recentposts">
		<h3><?php _e('My Recent Posts'); ?>
			<a href="edit.php" title="<?php _e('More posts...'); ?>">&raquo;</a>
		</h3>
		<ul>
			<?php
				foreach ($recentposts as $post) {
					if ($post->post_title == '')
						$post->post_title = sprintf(__('Post #%s'), $post->ID);
					echo "<li><a href='post.php?action=edit&amp;post=$post->ID'>";
					the_title();
					echo '</a></li>';
						}
				?>
		</ul>
	</div>
	<?php endif; ?>
<!--SCHEDULED POSTS-->
<?php
	if ( $scheduled = $wpdb->get_results("SELECT ID, post_title, post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_date_gmt > '$today' ORDER BY post_date ASC") ) :
?> 
	<div id="scheduledposts">
		<h3><?php _e('My Scheduled Posts:') ?></h3>
		<ul>
		<?php
			foreach ($scheduled as $post) {
				if ($post->post_title == '')
					$post->post_title = sprintf(__('Post #%s'), $post->ID);
				echo "<li>" . sprintf(__('%1$s in %2$s'), "<a href='post.php?action=edit&amp;post=$post->ID' title='" . __('Edit this post') . "'>$post->post_title</a>", human_time_diff( current_time('timestamp', 1), strtotime($post->post_date_gmt. ' GMT') ))  . "</li>";
				}
			?> 
		</ul>
	</div>
<?php endif; ?>

	<div id="stattotals">
		<h3><?php _e('My Daily Stats'); ?></h3>
			<?php
			// number of posts published
				$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
					if (0 < $numposts) $numposts = number_format($numposts); 
			// number of comments published
				$numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
					if (0 < $numcomms) $numcomms = number_format($numcomms);
			// number of categories
				$numcats = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->categories");
					if (0 < $numcats) $numcats = number_format($numcats);
			?>
			
		<p class="stats">
			<?php printf(__('You\'ve published %1$s <a href="%2$s" title="Posts">posts</a> so far which have been commented on %3$s <a href="%4$s" title="Comments">times.</a>'), $numposts, 'edit.php',  $numcomms, 'edit-comments.php'); ?>
		</p>
	</div>
<?php do_action('activity_box_end'); ?>

</div><!--/end stats-->
<!--DASHBOARD HOME-->
<p><?php _e('Use these quick links to get started:'); ?></p>
<!--QUICK LINKS-->
	<ul>
		<li>
			<?php $uri->setVar('controller','edit');$uri->setVar('task','post');	echo JHTML::_( 'link', $uri->toString(), 'Write a new post' );	?>
		</li>
		<li>
			<?php $uri->setVar('controller','edit');$uri->setVar('task','edit'); echo JHTML::_( 'link', $uri->toString(), 'Review your posts' );	?>
		</li>
		<li>
			<?php $uri->setVar('controller','edit');$uri->setVar('task','edit-comments'); echo JHTML::_( 'link', $uri->toString(), 'Moderate pending comments' ); ?>
		</li>
		<li>
			<?php $uri->setVar('controller','links'); $uri->setVar('task','link-add'); echo JHTML::_( 'link', $uri->toString(), 'Add a link to your blogroll'); ?>
		</li>
		<!-- li><a href="<?php JURI::base(); ?>themes.php"><?php _e('Change your mojoblog themeplate'); ?></a></li -->
	</ul>

<div id="devrss">
	<h3><?php _e('Latest from the mojo Developers Blog'); ?></h3>
	<p>
		<?php _e("Below is the latest mojo from our \"official\" Mojo development blog, click on a title to read the full entry. <br />
		If you need help with your Mojo please ask questions in our <a href='http://www.joomlify.com/forums/'>mojoBlog forums</a>."); ?>
	</p>


<?php
	/*$rss = @fetch_rss('http://feeds.feedburner.com/Joomlify-WeEatOurOwnDogfood');
		if ( isset($rss->items) && 0 != count($rss->items) ) {
	?>
<?php
	$rss->items = array_slice($rss->items, 0, 3);
		foreach ($rss->items as $item ) {
	?>
	
	<h4>
		<a href='<?php echo wp_filter_kses($item['link']); ?>'><?php echo wp_specialchars($item['title']); ?></a> &#8212; <?php printf(__('%s ago'), human_time_diff(strtotime($item['pubdate'], time() ) ) ); ?>
	</h4>
	<p>
		<?php echo $item['description']; ?>
	</p>
<?php
	}
}
?>

</div>

<?php
*/
///////////// 1.5 //////////////////////
require_once($mojo_exec_point.DS.'admin-footer.php');
///////////////////////////////////////
	
//require('./admin-footer.php');
?>
